package com.dalgen.mybatis.datasources;

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.alipay.oceanbase.OceanbaseDataSourceProxy;
import com.dalgen.mybatis.enums.TypeMapEnum;
import com.dalgen.mybatis.model.dbtable.Column;
import com.dalgen.mybatis.utils.CamelCaseUtils;
import com.dalgen.mybatis.utils.CmdUtil;
import com.google.common.collect.Lists;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.Validate;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.plugin.logging.SystemStreamLog;

import com.dalgen.mybatis.utils.ConfigUtil;

import javax.lang.model.element.ExecutableElement;

/**
 * Created by bangis.wangdf on 15/12/4. Desc
 */
public class DBConnectionFactory {
    /**
     * The constant LOG.
     */
    private static final Log LOG = new SystemStreamLog();

    /**
     * Gets connection.
     *
     * @return the connection
     */
    public static Connection getConnection() {
        Connection connection = null;
        try {
            LOG.info("==== init connection");
            if (connection == null) {
                if (StringUtils.equalsIgnoreCase("ob", ConfigUtil.getCurrentDb().getType())) {
                    connection = OBConnection.getConnection(ConfigUtil.getCurrentDb());
                    Validate.notNull(connection, "====connection error ob");
                } else {
                    connection = JdbcConnection.getConnection(ConfigUtil.getCurrentDb());
                    Validate.notNull(connection, "====connection error mysql");
                }

            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return connection;

    }

}
